package com.rc.saas.mini.service.tenant;

import com.rc.saas.mini.mapper.tenant.TenantUserMapper;
import com.rc.saas.mini.model.tenant.TenantUser;
import com.rc.saas.mini.model.tenant.TenantUserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TenantUserServiceImpl implements TenantUserService {

    @Autowired
    private TenantUserMapper tenantUserMapper;

    @Override
    public TenantUserMapper getMapper() {
        return tenantUserMapper;
    }

    @Override
    public TenantUser selectByMobile(String mobile) {
        TenantUserExample example = new TenantUserExample();
        example.createCriteria().andMobileEqualTo(mobile);
        List<TenantUser> tenantUsers = tenantUserMapper.selectByExample(example);
        if (tenantUsers != null && tenantUsers.size() > 0) {
            return tenantUsers.get(0);
        }
        return null;
    }

    @Override
    public TenantUser selectByEnterpriseId(Long enterpriseId) {
        TenantUserExample example = new TenantUserExample();
        example.createCriteria().andEnterpriseIdEqualTo(enterpriseId);
        return tenantUserMapper.selectByExample(example).stream().findFirst().orElseGet(() -> null);
    }
}
